package com.supply.dl.widget.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import butterknife.BindView;
import com.chad.library.adapter.base.BaseViewHolder;
import com.supply.dl.R;
import com.supply.dl.activity.TransferGoodsConfirmDetailActivity;
import com.supply.dl.bean.TransGoodsBean;
import com.supply.dl.utils.Utils;

import java.util.ArrayList;
import java.util.List;

public class TakeDepotAdapter extends RecyclerView.Adapter<TakeDepotAdapter.MyViewHolder>
{
	private Context mContext;
	private List<TransGoodsBean> transGoodsBeanList = new ArrayList<TransGoodsBean>();

	public TakeDepotAdapter(Context context, List<TransGoodsBean> goodList)
	{
		this.mContext = context;
		this.transGoodsBeanList = goodList;
	}

	@Override public TakeDepotAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
	{
		return new TakeDepotAdapter.MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_change_take_delivery, parent, false));
	}

	@Override public void onBindViewHolder(TakeDepotAdapter.MyViewHolder holder, int position)
	{
		final TransGoodsBean transGoodsBean = transGoodsBeanList.get(position);
		holder.txtName.setText("移库订单号" + transGoodsBean.noticeOrderNo);
		holder.txtTime.setText(Utils.long2Str(Long.valueOf(transGoodsBean.addTime)));
		holder.txtType.setText(transGoodsBean.orderTypeName);
		holder.txtStatus.setText(transGoodsBean.noticeOrderStatusName);
		holder.txtOut.setText("出库仓库：" + transGoodsBean.tfOutWhName);
		holder.txtIn.setText("入库仓库：" + transGoodsBean.tfOutWhName);
		holder.layoutRoot.setOnClickListener(new View.OnClickListener()
		{
			@Override public void onClick(View view)
			{
				Intent intent = new Intent(mContext, TransferGoodsConfirmDetailActivity.class);
				intent.putExtra("NOTICE_ORDER_NUM", transGoodsBean.noticeOrderId);
				intent.putExtra("orderBean",transGoodsBean);
				mContext.startActivity(intent);
			}
		});
	}

	@Override public int getItemCount()
	{
		return transGoodsBeanList.size();
	}

	class MyViewHolder extends BaseViewHolder
	{
		@BindView(R.id.txt_name) TextView txtName;
		@BindView(R.id.txt_out) TextView txtOut;
		@BindView(R.id.txt_in) TextView txtIn;
		@BindView(R.id.txt_status) TextView txtStatus;
		@BindView(R.id.txt_time) TextView txtTime;
		@BindView(R.id.txt_type) TextView txtType;
		@BindView(R.id.layout_root) LinearLayout layoutRoot;

		public MyViewHolder(View itemView)
		{
			super(itemView);
			txtName = (TextView) itemView.findViewById(R.id.txt_name);
			txtOut = (TextView) itemView.findViewById(R.id.txt_out);
			txtIn = (TextView) itemView.findViewById(R.id.txt_in);
			txtType = (TextView) itemView.findViewById(R.id.txt_type);
			txtStatus = (TextView) itemView.findViewById(R.id.txt_status);
			txtTime = (TextView) itemView.findViewById(R.id.txt_time);
			layoutRoot = (LinearLayout) itemView.findViewById(R.id.layout_root);
		}
	}
}
